<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%
	String userId = (String)request.getSession().getAttribute(com.wing.common.Constants.SESSION_USER_ID); 
%>
<html>
	<head>
		<script type="text/javascript">
		
			$(function(){
				//加载两个要使用json分页的组件
		        loadGird("frm", 1);
			})
				
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		   			       var keyValue = n.id;
			       row.find(".klId").attr("value",n.id);
			   	
			       row.find(".klname").text(n.name);
			   	
			       row.find(".klpicpath").text(n.picpath);
			   	
			       row.find(".klftlpath").text(n.ftlpath);
			   	
			       row.find(".klpictype").text(n.pictype);
			   	
			       row.find(".klispub").text(n.ispub=="<%=com.wing.cms.domain.Template.ISPUB_TRUE %>"?"是":"否");
			   	
		 		   row.attr("id","ready"+i);
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");
		       });   
			}
			
			var deltemplates = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
					alert("成功删除"+msg+"条记录！");
					document.location.reload();
				}
				}
				if(confirm('您确认要删除吗？')){
					document.getElementById("frm").action="<%=path%>/cms/template/deltemplates";
					$('#frm').ajaxSubmit(options);
				}
			}
			function addtemplate(){
	            opendailog("{src:'<%=path %>/cms/template/toForm/0',title:'模板属性',width:600,height:300,savefunc:'savefunc'}",window);
			}
			
			function modifytemplate(id){
				if(checkOnlySel()){
					opendailog("{src:'<%=path %>/cms/template/toForm/"+getCheckedObj("chk")[0].value+"',title:'模板属性',width:600,height:300,savefunc:'savefunc'}",window);
				}
			}
			
			function savefunc(frame){
				var retv = frame.contentWindow.save()
				if(retv=="success"){
					alertMsg("保存成功！");
					reloadGrid("frm", 1);
				}
				return retv;
			}
		</script>
	</head>
<body>
<form name="frm" method="post" style="margin: 0" action="<%=path%>/cms/template/list" id="frm">
		<%if(com.wing.common.Constants.SYSTEM_SUPERADMIN_ID.equals(userId)){ %>
		<table width="100%">
			<tr>
				<td height="2px"></td>
			</tr>
			<tr><td align="right">
				<input type="button" onclick="addtemplate();" class="button4_nbw" value="添加" />
				<input type="button" onclick="modifytemplate();" class="button4_nbw" value="修改" />
				<input type="button" onclick="deltemplates()" class="button4_nbw" value="删除" />
				&nbsp;&nbsp;
				</td>
			</tr>
		</table>
		<%} %>
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px" >
						<input type="checkbox" class="allCheck" />
					</td>
		      		<td width="40%">
						模板名称
					</td>   
		      		<td>
						图片路径
					</td>   
		      		<td>
						模板路径
					</td>   
		      		<td>
						图片类型
					</td>   
		      		<td width="10%">
						是否公用
					</td>   
				</tr>
			</thead>
			<tbody>
				<tr class="template klId">
					<td width="40px" class="idCheck">
						<input type="checkbox" name="chk" class="klId" />
					</td>
		   		    <td class="klname niceTable-left"></td>
		   		    <td class="klpicpath niceTable-left"></td>
		   		    <td class="klftlpath niceTable-left"></td>
		   		    <td class="klpictype niceTable-left"></td>
		   		    <td class="klispub niceTable-left"></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td style="border-right: none">
						<img class="loading"
							src="/resources/skins/default/images/large-loading.gif" width="20px"
							class="hidden" />
					</td>
					<td colspan="5" style="border-left: none" class="txtRight">
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
		</center>
	</form>
</body>
</html>
